package com.aaa.system.Controller.Api;

import com.aaa.entity.DictType;
import com.aaa.system.aop.annotation.Log;
import com.aaa.system.service.DictTypeService;
import com.aaa.system.vo.DictTypeVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("system/api/dict/typeData")
public class ApiDictTypeController {

    @Autowired
    private DictTypeService dictTypeService;

    /**
     * 同步缓存将字典同步到缓存中  从缓存中查询
     * @return
     */
    @GetMapping("cacheAsync")
    public Result<String> getCacheAsync(){
        return dictTypeService.getAllDictList();
    }

    /**
     *查询全部数据 分页 模糊
     */
    @PostMapping("getAllDictList")
    public Result<IPage<DictType>> getDictData(@RequestBody DictTypeVo dictTypeVo){
        return dictTypeService.getDictTypeList(dictTypeVo);
    }
    /**
     * 类型跳转 查询所有的DictType
     */
    @GetMapping("getAllDict")
    public Result<List<DictType>> getAllDict(){
        return dictTypeService.getAllDict();
    }

    /**
     *添加 修改 字典
     */
    @PostMapping("addDictType")
    @Log(title = "添加/修改字典",business_type = "1")
    public Result<Boolean> saveOrUpdDictType(@RequestBody DictType dictType){
        return dictTypeService.saveOrUpdDictType(dictType);
    }

    /**
     *删除字典 批量删除
     */
    @DeleteMapping("delDictType/{dictIds}")
    @Log(title = "删除字典",business_type = "3")
    public Result<Boolean> delDictType(@PathVariable Long[] dictIds){
        return dictTypeService.delDictType(dictIds);
    }
}
